//
//  TCM_Const.swift
//  TCM_TradingProject
//
//  Created by 吕春海 on 2018/8/13.
//  Copyright © 2018年 lvchunhai. All rights reserved.
//

import Foundation
import UIKit

// ===================================变量宏定义=========================================
//appKey相关
public let BKLUMengKey = "5b4e9a038f4a9d22090000a5"
public let BKLQQAppKey = "6QvBXK7M4Q0BpweH"
public let BKLQQAppID = "1106347647"
public let BKLWXAppKey = "wx5b6536575f22fe33"
public let BKLWXSecuty = "e5f2a4f77da4a1bf99aa9bc722eeceac"

//系统相关
public let TCM_iOSBase = 8.0
public let TCM_iOSGreaterOrEqualToiOS8 = ((Double(UIDevice.current.systemVersion) ?? TCM_iOSBase) > 8.0 ) ? true : false;
public let TCM_iOSGreaterOrEqualToiOS9 = ((Double(UIDevice.current.systemVersion) ?? TCM_iOSBase) >= 9.0 ) ? true : false;
public let TCM_iOSGreaterOrEqualToiOS10 = ((Double(UIDevice.current.systemVersion) ?? TCM_iOSBase) >= 10.0 ) ? true : false;
public let TCM_iOSGreaterOrEqualToiOS11 = ((Double(UIDevice.current.systemVersion) ?? TCM_iOSBase) >= 11.0 ) ? true : false;

//设备宽高、机型
public let TCM_ScreenHeight = UIScreen.main.bounds.size.height
public let TCM_ScreenWidth = UIScreen.main.bounds.size.width
public let TCM_StatusBarHeight = UIApplication.shared.statusBarFrame.size.height
public func TCM_NavBarHeight() -> CGFloat {
    if TCM_ScreenHeight == 812.0 {
        return 88
    }else{
        return 64
    }
}

//状态栏高度
public func TCM_StatusHeight() -> CGFloat {
    if TCM_ScreenHeight == 812.0 {
        return 44
    }else{
        return 20
    }
}

//iphone X 底部安全区域
public func TCM_SafeBottomHeight() -> CGFloat {
    if TCM_ScreenHeight == 812.0 {
        return 34
    }else{
        return 0
    }
}

//安全区域 + tabbar高度
public func TCM_SafeBottomAndTabbarHeight() -> CGFloat {
    if TCM_ScreenHeight == 812.0 {
        return 82
    }else{
        return 48
    }
}

// 设置颜色值
// 通过 十六进制与alpha来设置颜色值  （ 样式： 0xff00ff ）
public func TCM_HexRGB (_ rgbValue : Int, _ alpha : Float = 1) -> UIColor {
    return UIColor(red: CGFloat(CGFloat((rgbValue & 0xFF0000) >> 16)/255), green: CGFloat(CGFloat((rgbValue & 0xFF00) >> 8)/255), blue: CGFloat(CGFloat(rgbValue & 0xFF)/255), alpha: CGFloat(alpha))
}

// 通过 red 、 green 、blue 、alpha 颜色数值
public func TCM_RGBAlpa (_ r: Float, _ g: Float , _ b: Float , _ a: Float = 1 ) -> UIColor {
    return UIColor.init(red: CGFloat(CGFloat(r)/255.0), green: CGFloat(CGFloat(g)/255.0), blue: CGFloat(CGFloat(b)/255.0), alpha: CGFloat(a))
}

//设置字体
public func TCM_SystemFont (_ fontSize:CGFloat) -> UIFont {
    return UIFont.systemFont(ofSize: fontSize);
}

//粗体
public func TCM_BoldFont (_ fontSize:CGFloat) -> UIFont {
    return UIFont.boldSystemFont(ofSize: fontSize);
}

//通用颜色
public func TCM_ThemeColor () -> UIColor {
    return TCM_HexRGB(0x693C26)
}

/*  使用NSUserDefaults对普通数据对象储存   */


/// 存储
///
/// - Parameters:
///   - obj: value
///   - key: key
public func TCM_SaveUserDefault (_ obj: Any, _ key: String) {
    UserDefaults.standard.set(obj, forKey: key)
}

/// 根据key取值
///
/// - Parameter key: key
public func TCM_GetUserDefault (_ key: String) -> Any? {
    return UserDefaults.standard.value(forKey: key)
}

